var _RESERVE_INFO_ROOM_INDICATOR 	= "reserveInfoRoomIndicator";

function validateTypeOfRoom(){
	var typeOfRoomObj		= document.getElementById("typeOfRoom");
	
	//createZoneComboList(typeOfRoomObj.value);	
}
function validateZone(){
	var typeOfRoomObj 		= document.getElementById("typeOfRoom");
	var zoneObj				= document.getElementById("zone");
	//createFloorComboList(typeOfRoomObj.value, zoneObj.value);	
}

function createZoneComboList(typeOfRoom){
    var params		= "subTypeOfRoom=" + typeOfRoom;

    //clear combo
    document.getElementById("zone").options.length 	= 0;
    document.getElementById("floor").options.length = 0;
    
    document.getElementById(_RESERVE_INFO_ROOM_INDICATOR).style.display = "inline";
    isdnSendRequest("reserveInfoType_getZoneListJSON.action", params , "POST", callbackCreateZoneComboList);
}

callbackCreateZoneComboList = function() {
    var ready = req.readyState;
    //  console.debug(ready);
    var jsonObject=null;
    if ( ready == 4 ){
        if(req.status == 200) {
            jsonObject=eval( "("+ req.responseText +")" );

            if(jsonObject.object.data['com.appsindy.reserv.bo.Combo']){            	
                var detail  	= jsonObject.object.data['com.appsindy.reserv.bo.Combo'];
                var size 		= detail.length;
                var isIE 		= detect_browser();
                var zone 		= document.getElementById("zone");
                var newOption 	= window.document.createElement("option");
                newOption.value = "";
                newOption.text 	= "All";
                if(isIE==true)
                	zone.add(newOption);
                else
                	zone.appendChild(newOption);
                
                if(size){
                	for(var i = 0; i < size; i ++) {
	                    newOption 		= window.document.createElement("option");
	                    newOption.value = detail[i].key;
	                    newOption.text 	= detail[i].key;
	                    if(isIE==true)
	                    	zone.add(newOption);
	                    else
	                    	zone.appendChild(newOption); 
                	}
                }else{
                    newOption 		= window.document.createElement("option");
                    newOption.value = detail.key;
                    newOption.text 	= detail.key;
                    if(isIE==true)
                    	zone.add(newOption);
                    else
                    	zone.appendChild(newOption);                	
                }
                var typeOfRoomObj	= document.getElementById("typeOfRoom"); 
                var zoneObj			= document.getElementById("zone"); 
                createFloorComboList(typeOfRoomObj.options[typeOfRoomObj.selectedIndex].value, zoneObj.options[zoneObj.selectedIndex].value);
            }
            
            document.getElementById(_RESERVE_INFO_ROOM_INDICATOR).style.display = "none";
        }
    }
};
function createFloorComboList(typeOfRoom, zone){
    var params		= "subTypeOfRoom=" + typeOfRoom + "&subZone=" + zone;

    //clear combo
    document.getElementById("floor").options.length = 0;

    document.getElementById(_RESERVE_INFO_ROOM_INDICATOR).style.display = "inline";
    isdnSendRequest("reserveInfoType_getFloorListJSON.action", params , "POST", callbackCreateFloorComboList);
}

callbackCreateFloorComboList = function() {
    var ready = req.readyState;
    //  console.debug(ready);
    var jsonObject=null;
    if ( ready == 4 ){
        if(req.status == 200) {
            jsonObject=eval( "("+ req.responseText +")" );

            if(jsonObject.object.data['com.appsindy.reserv.bo.Combo']){            	
                var detail  	= jsonObject.object.data['com.appsindy.reserv.bo.Combo'];
                var size 		= detail.length;
                var isIE 		= detect_browser();
                var floor		= document.getElementById("floor");
                var newOption 	= window.document.createElement("option");
                newOption.value = "";
                newOption.text 	= "All";
                if(isIE==true)
                	floor.add(newOption);
                else
                	floor.appendChild(newOption);
                
                if(size){
                	for(var i = 0; i < size; i ++) {
	                    newOption 		= window.document.createElement("option");
	                    newOption.value = detail[i].key;
	                    newOption.text 	= detail[i].key;
	                    if(isIE==true)
	                    	floor.add(newOption);
	                    else
	                    	floor.appendChild(newOption); 
                	}
                }else{
                    newOption 		= window.document.createElement("option");
                    newOption.value = detail.key;
                    newOption.text 	= detail.key;
                    if(isIE==true)
                    	floor.add(newOption);
                    else
                    	floor.appendChild(newOption);                	
                }
            }
            document.getElementById(_RESERVE_INFO_ROOM_INDICATOR).style.display = "none";
        }
    }
};

function addRowRoomReserve(colList){
	colList				= colList==null?new Array():colList;
    var	roomId        	= colList["roomId"]==null?"":colList["roomId"];
    var	dateFrom        = colList["dateFrom"]==null?"":colList["dateFrom"];
    var	dateTo        	= colList["dateTo"]==null?"":colList["dateTo"];
    var	typeOfRoomId   	= colList["typeOfRoomId"]==null?"":colList["typeOfRoomId"];
    var	typeOfRoom      = colList["typeOfRoom"]==null?"":colList["typeOfRoom"];
    //var	zone     		= colList["zone"]==null?"":colList["zone"];
    //var	floor       	= colList["floor"]==null?"":colList["floor"];
    var	day       		= colList["day"]==null?"":colList["day"];
    //var	qtyRoomPerDay   = colList["qtyRoomPerDay"]==null?"":colList["qtyRoomPerDay"];
    var	ratePerRoom     = colList["ratePerRoom"]==null?"0":colList["ratePerRoom"];
    var	totalAmount     = colList["totalAmount"]==null?"0":colList["totalAmount"];
    var	breakfast       = colList["breakfast"]==null?"":colList["breakfast"];
    var	errCode       	= colList["errCode"]==null?"":colList["errCode"];
    var	errMsg       	= colList["errMsg"]==null?"":colList["errMsg"];

    var tblBody         = document.getElementById(_RESERVE_TABLE);
    var size            = tblBody.rows.length;
    var newRow          = tblBody.insertRow(-1);
    newRow.height       = "30px";
    newRow.className	= "tBody";

    //Room
    var tdRoom    		= document.getElementById("templateRoom");
    var tmpRoom   		= document.getElementsByName("colRoomId");
    var len				= tmpRoom.length;     
    if(len){
    	tmpRoom[len-1].value	= roomId;
    }else{
    	tmpRoom.value      		= roomId;
    }
    
    var newCell;
    var rowIndex        = 0;
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<a onclick="delRowRoomReserve(this)"><img src="./images/calendar/close.gif" /></a>';
    newCell.setAttribute("align","center");
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<input type="checkbox" onclick="checkboxRoomDetail();"/>';
    newCell.setAttribute("align","center");
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<img src="./images/status_R.png" />';
    newCell.setAttribute("align","center");
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = size+1;
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = tdRoom.innerHTML;
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<input type="text" name="colDateFrom" size="10" maxlength="10" value="'+dateFrom+'" onchange="setDetailIndex(this);validateColDateFrom()" class="iNL"/>' +
    					  '&nbsp;<img style="cursor:hand" src="./images/calendar.gif" />';
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<input type="text" name="colDateTo" size="10" maxlength="10" value="'+dateTo+'" onchange="setDetailIndex(this);validateColDateTo()" class="iNL"/>' +
	  					  '&nbsp;<img style="cursor:hand" src="./images/calendar.gif" />';
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<input type="text" name="colTypeOfRoom" size="10" maxlength="8" value="'+typeOfRoom+'" readonly class="iDL"/>';
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<input type="text" name="colDay" size="10" maxlength="8" value="'+day+'" readonly class="iDL"/>';
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<input type="text" name="colRatePerRoom" size="10" maxlength="8" value="'+ratePerRoom+'" onchange="setDetailIndex(this);validateColRatePerRoom()" onkeypress="return text_OnKeyPress_NumberOnlyAndDot();" class="iNR"/>';
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<input type="text" name="colTotalAmount" size="10" maxlength="8" value="'+totalAmount+'" readonly class="iDR"/>';
    newCell             = newRow.insertCell(rowIndex++);
    newCell.innerHTML   = '<input type="checkbox" name="colBreakfastTmp" value="1" onclick="setDetailIndex(this);validateColBreakfast()" />';
    newCell             = newRow.insertCell(rowIndex++);
    var errRoomRate		= document.getElementById("msgErrorManyRoom").innerText + ' ' + errMsg;
    newCell.innerHTML   = errMsg!=""?'<b><font color="red" title="'+errRoomRate+'">X</font></b>':'';
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("display", "none");
    newCell.innerHTML   = '<input type="hidden" name="colTypeOfRoomId" />' +
    					  '<input type="hidden" name="colBreakfast" />';
    
    /*
    var typeOfRoomObj		= document.getElementsByName("colTypeOfRoomId")[size];
    var typeOfRoomNameObj	= document.getElementsByName("colTypeOfRoom")[size];
    typeOfRoomNameObj.value	= typeOfRoomObj.options[typeOfRoomObj.selectedIndex].text;
    createZoneCombo(typeOfRoomObj.options[typeOfRoomObj.selectedIndex].value, size);
    if(zone != ""){
    	document.getElementsByName("colZone")[size].value = zone;
    }
    if(floor != ""){
    	document.getElementsByName("colFloor")[size].value = floor;
    }
    
    cal1_detail = new YAHOO.widget.Calendar("cal1_detail", "cal1Container");
    cal1_detail.cfg.setProperty("MDY_DAY_POSITION", 1);
    cal1_detail.cfg.setProperty("MDY_MONTH_POSITION", 2);
    cal1_detail.cfg.setProperty("MDY_YEAR_POSITION", 3);
    cal1_detail.selectEvent.subscribe(getDateDetail, cal1_detail, true);
    cal1_detail.renderEvent.subscribe(setupListenersDetail, cal1_detail, true);    
    YAHOO.util.Event.addListener(document.getElementsByName("colDateFrom")[size], 'click', showCalDetail);
    YAHOO.util.Event.addListener(document.getElementsByName("colDateFrom")[size], 'blur', hideCalDetail);
    YAHOO.util.Event.addListener(document.getElementsByName("colDateTo")[size], 'click', showCalDetail);
    YAHOO.util.Event.addListener(document.getElementsByName("colDateTo")[size], 'blur', hideCalDetail);
    */
}

function delRowRoomReserve(detailId){
    //var rowIndex        = obj.parentElement.parentElement.rowIndex-2;
    
    //var tblBody         = document.getElementById(_RESERVE_TABLE);
    if(confirm('Do you want to delete?')){
    	document.getElementById("serviceDetailId").value	= detailId;
    	document.getElementById("btnDeleteDetailReserveInfoRoom").click();
    	
        //tblBody.deleteRow(rowIndex);
        
        //calculateRoomTotalAmount();
    }
}

/*
function addRowRoomAvailable(roomId, dateGen, typeOfRoomId, typeOfRoom, price){
	colList					= new Array();
    colList["roomId"]		= roomId;
    colList["dateFrom"]		= dateGen;
    colList["dateTo"]		= dateGen;
    colList["typeOfRoomId"]	= typeOfRoomId;
    colList["typeOfRoom"]	= typeOfRoom;
    var _day				= calculateBetweenDate(dateGen, dateGen)+1;
    colList["day"]			= _day;
    colList["ratePerRoom"]	= price;
    var _price				= price==''?0:parseFloat(removeCommas(price));
    var _total				= _price * 1 * _day;
    colList["totalAmount"]	= tryNumberFormatValue(_total, true, 0);
    
    addRowRoomReserve(colList);
    
    calculateRoomTotalAmount();
}
*/

function calculateRoomTotalAmount(){
	var colDayObj 			= document.getElementsByName("colDay")[_ROW_INDEX];
	var colRatePerRoom 		= document.getElementsByName("colRatePerRoom")[_ROW_INDEX];
	var colTotalAmount 		= document.getElementsByName("colTotalAmount")[_ROW_INDEX];
	var grandTotalAmount 	= document.getElementById("grandTotalAmount");
	
	var calDay				= colDayObj.value==''?0:parseFloat(removeCommas(colDayObj.value));
	var calRate				= colRatePerRoom.value==''?0:parseFloat(removeCommas(colRatePerRoom.value));
	var calTotal			= calRate * calDay;
	
	
	colTotalAmount.value	= tryNumberFormatValue(calTotal, true, 0);
	
	//calculate all totalAmount
    var tblBody             = document.getElementById(_RESERVE_TABLE);
    var size                = tblBody.rows.length;
    var total				= 0;
    for(var i=0; i<size; i++){
    	var totalObj 		= document.getElementsByName("colTotalAmount")[i];
    	total			   += totalObj.value==''?0:parseFloat(removeCommas(totalObj.value));
    }
	grandTotalAmount.innerText	= tryNumberFormatValue(total, true, 0);
}

function validateDateFromInfoRoom(obj) {
	if(validateDateFormat(obj)){
		var dateFrom 	= document.getElementById("dateFromInfoRoom");
		var dateTo 		= document.getElementById("dateToInfoRoom");
		
		if(dateFrom.value != "" && dateTo.value != ""){
			var _day		= calculateBetweenDate(dateFrom.value, dateTo.value);
			if(_day <= 0){
				alert("Please input dateFrom less than dateTo.");
				dateFrom.value = "";
				dateFrom.focus();
			}
		}		
	}
}
function validateDateToInfoRoom(obj) {
	if(validateDateFormat(obj)){
		var dateFrom 	= document.getElementById("dateFromInfoRoom");
		var dateTo 		= document.getElementById("dateToInfoRoom");
		
		if(dateFrom.value != "" && dateTo.value != ""){
			var _day		= calculateBetweenDate(dateFrom.value, dateTo.value);
			if(_day <= 0){
				alert("Please input dateTo more than dateFrom.");
				dateTo.value = "";
				dateTo.focus();
			}
		}
	}
}

function gotoReserveDetailByAdd(){
	var groupId			= document.getElementById("groupId").value;
	var serviceHeaderId	= document.getElementById("serviceHeaderId").value;
	
	var params	= "?groupId=" + groupId + "&serviceHeaderId=" + (serviceHeaderId?serviceHeaderId:'');
	showReserveDetailPopup(params);
}
function gotoReserveDetailByCustomer(customerId){
//    alert('customerId='+customerId);
    showReserveDetailPopup();
}
function gotoReserveDetailByRoom(typeOfRoomId, roomId, dateGen){
	var groupId	= document.getElementById("groupId").value;
	var serviceHeaderId	= document.getElementById("serviceHeaderId").value;

	var params	= "?groupId=" + groupId + "&serviceHeaderId=" + (serviceHeaderId?serviceHeaderId:'');
		params += "&typeOfRoomId=" + (typeOfRoomId?typeOfRoomId:'') + "&roomId=" + (roomId?roomId:'') + "&dateGen=" + dateGen;
    showReserveDetailPopup(params);
}
function gotoReserveDetailById(serviceDetailId){
	var groupId	= document.getElementById("groupId").value;
	var serviceHeaderId	= document.getElementById("serviceHeaderId").value;

	var params	= "?groupId=" + groupId + "&serviceHeaderId=" + (serviceHeaderId?serviceHeaderId:'');	
		params += "&serviceDetailId=" + (serviceDetailId?serviceDetailId:'0');
	showReserveDetailPopup(params);
}

var tmp_popup;
function showReserveDetailPopup(params) {

    var popupHeight = 450;
    var popupWidth = 950;

    var posX = parseInt((window.screen.availWidth - popupWidth) / 2);
    var posY = parseInt((window.screen.availHeight - popupHeight) / 2);

    if (posX < 0) { posX = 0; }
    if (posY < 0) { posY = 0; }

    var url		= "reserveDetail_execute.action";
    
    params		= params==null?'':params;
    var popup 	= window.open(url + params, 'reserveDetail', "location=no,menubar=no,resizable=no,status=yes,toolbar=no,width="+ popupWidth +",height="+ popupHeight+",scrollbars=no,left=" + posX + ",top=" + posY , "true");
    tmp_popup 	= popup;
    if (window.focus) {tmp_popup.focus();}
    return popup;
}

dojo.event.topic.subscribe("/beforeSearchInfoRoom", function(event, widget){
    try{
		var dateFrom 	= document.getElementById("dateFromInfoRoom");
		var dateTo 		= document.getElementById("dateToInfoRoom");
		
		if(dateFrom.value == ""){
			alert("Please input dateFrom");
			dateFrom.focus();
			event.cancel = true;
		}else if(dateTo.value == ""){
			alert("Please input dateTo");
			dateTo.focus();
			event.cancel = true;
		}
    }catch(err ) {
         alert("Javascript error in this reserve info page beforeSearchInfoRoom main function() [Error: " + err.message + "]");
         event.cancel = true;
    }
});
dojo.event.topic.subscribe("/beforeRoomBack", function(event, widget){
    try{
    	var msg = document.getElementById("msgRoomConfirmBack").innerText;
        if(!confirm(msg)){
        	event.cancel = true;
        }

    }catch(err ) {
         alert("Javascript error in this reserve info page beforeRoomBack main function() [Error: " + err.message + "]");
         event.cancel = true;
    }
});

function btnInfoRoomBackOnClick(obj){
	var msg = document.getElementById("msgRoomConfirmBack").innerText;
    if(confirm(msg)){
        url = "reserveInfoRoom_back.action";
        document.getElementById("frmReserveInfoRoom").action = url;
        document.getElementById("frmReserveInfoRoom").submit();
        return true;
    }
    return false;
}

function btnInfoRoomCancelOnClick(obj){
	var msg = document.getElementById("msgRoomConfirmCancelJob").innerText;
    if(confirm(msg)){
    	
    	var params	 = "reserveInfoRoomVO.serviceHeaderId=" + document.getElementById("serviceHeaderId").value;
		params	+= "&reserveInfoRoomVO.serviceStatus=" + document.getElementById("serviceStatus").value;
		
	    document.getElementById(_RESERVE_INFO_ROOM_INDICATOR).style.display = "inline";
	    isdnSendRequest("reserveInfoRoom_checkCancelJobJSON.action", params , "POST", callbackCheckCancelJob);
    	    	
        return true;
    }
    return false;
}
callbackCheckCancelJob = function() {
    var ready = req.readyState;
    //  console.debug(ready);
    var jsonObject=null;
    if ( ready == 4 ){
        if(req.status == 200) {
            jsonObject=eval( "("+ req.responseText +")" );

            if(jsonObject.object.data.errMsg != null && jsonObject.object.data.errMsg != ''){
            	alert(jsonObject.object.data.errMsg);              	
            }else{
                url = "reserveInfoRoom_back.action";
                document.getElementById("frmReserveInfoRoom").action = url;
                document.getElementById("frmReserveInfoRoom").submit();            	
            }
            
            document.getElementById(_RESERVE_INFO_ROOM_INDICATOR).style.display = "none";
        }
    }
};

function gotoReservePayment(){
    var tblBody         = document.getElementById(_RESERVE_TABLE);
    var size            = tblBody.rows.length;
    var isCheck			= false;
    var strDetailId		= "";
    var arrCheckbox 	= document.getElementsByName("colServiceDetailId");
    for(var i=0; i<size; i++){
    	if(arrCheckbox[i].checked){
    		isCheck = true;
    		if(strDetailId == "") 	strDetailId += arrCheckbox[i].value;
    		else					strDetailId += ","+arrCheckbox[i].value;
    	}
    }
	
    if(!isCheck){
    	alert("Please select checkbox.");
    	return false;
    }
    
	var groupId	= document.getElementById("groupId").value;
	var serviceHeaderId	= document.getElementById("serviceHeaderId").value;
	
	var params	= "?groupId=" + groupId +"&serviceHeaderId=" + (serviceHeaderId?serviceHeaderId:'0');
		params	+= "&arrServiceDetailId=" + strDetailId;
	showReservePaymentPopup(params);
}

function showReservePaymentPopup(params) {
    var popupHeight = 650;
    var popupWidth = 950;

    var posX = parseInt((window.screen.availWidth - popupWidth) / 2);
    var posY = parseInt((window.screen.availHeight - popupHeight) / 2);

    if(posX < 0) { posX = 0; }
    if(posY < 0) { posY = 0; }
    
    var url		= "reservePayment_execute.action";
    
    params		= params==null?'':params;
    var popup 	= window.open(url + params, "reservePayment", "location=no,menubar=no,resizable=yes,status=yes,toolbar=no,width="+ popupWidth +",height="+ popupHeight+",scrollbars=yes,left=" + posX + ",top=" + posY , "true");                
    tmp_popup 	= popup;
    return popup;
}

function refreshReserveInfoRoom(){
	var btnObj = document.getElementById("btnRefreshReserveInfoRoom");
	btnObj.click();
}
//function backReserveOverview(){
//    url = "reserveInfoRoom_back.action";
//    document.getElementById("frmReserveInfoRoom").action = url;
//    document.getElementById("frmReserveInfoRoom").submit();
//}

function showReservePrintReceiptPopup(params) {
    var popupHeight = 400;
    var popupWidth = 600;
    var posX = parseInt((window.screen.availWidth - popupWidth) / 2);
    var posY = parseInt((window.screen.availHeight - popupHeight) / 2);
    
    if(posX < 0){ posX = 0; }
    if(posY < 0){ posY = 0; }
    
    var url = "reservePrintReceipt_execute.action";
    params = params==null?'':params;
    var popup = window.open( url + params, 'reservePrintReceipt'
    					   , "location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,width="+ popupWidth +",height="+ popupHeight+",left=" + posX + ",top=" + posY , "true");                
    tmp_popup = popup;
    return popup;
}

function checkboxRoomAll(obj){
    var tblBody         = document.getElementById(_RESERVE_TABLE);
    var size            = tblBody.rows.length;
    var isCheck			= obj.checked;
    var arrCheckbox 	= document.getElementsByName("colServiceDetailId");    
    for(var i=0; i<size; i++){
    	arrCheckbox[i].checked = isCheck;
    }
}

function checkboxRoomDetail(){
    var tblBody         = document.getElementById(_RESERVE_TABLE);
    var size            = tblBody.rows.length;
    var isCheck			= false;
    var checkboxAll 	= document.getElementById("checkboxAll");    
    var arrCheckbox 	= document.getElementsByName("colServiceDetailId");    
    for(var i=0; i<size; i++){
    	if(arrCheckbox[i].checked){
    		isCheck = true;
    	}else{
    		isCheck = false;
    		break;
    	}
    }
    if(isCheck){
    	checkboxAll.checked = true;
    }else{
    	checkboxAll.checked = false;
    }
}

function checkReserveDetailAction(action){
    var tblBody         = document.getElementById(_RESERVE_TABLE);
    var size            = tblBody.rows.length;
    var isCheck			= false;
    var isFail			= false;
    var strDetailId		= "";
    var strDateTo		= "";
    var strDateFrom		= "";
    var strRoomId		= "";
    var changeStatus	= document.getElementById("authorizeChangbackStatus");
    var arrCheckbox 	= document.getElementsByName("colServiceDetailId");
    var arrServiceStatus= document.getElementsByName("colServiceStatus");
    var arrDateFrom		= document.getElementsByName("colServiceStartDate");
    var arrDateTo		= document.getElementsByName("colServiceEndDate");
    var arrRoomId		= document.getElementsByName("colRoomId");
    var arrStatus		= {"RESERVED":0, "BOOKED":1, "CHECKIN":2, "CHECKOUT":3};
    for(var i=0; i<size; i++){
    	if(arrCheckbox[i].checked){
    		isCheck = true;
    		if(strDetailId == ""){
    			strDetailId += arrCheckbox[i].value;
    			strDateFrom += arrDateFrom[i].value;
    			strDateTo 	+= arrDateTo[i].value;
    			strRoomId 	+= arrRoomId[i].value;
    		}else{
    			strDetailId += ","+arrCheckbox[i].value;
    			strDateFrom += ","+arrDateFrom[i].value;
    			strDateTo 	+= ","+arrDateTo[i].value;
    			strRoomId 	+= ","+arrRoomId[i].value;
    		}

        	if(changeStatus.value == 'N'){
        		if(arrStatus[action] <= arrStatus[arrServiceStatus[i].value]){
        			isFail = true;
        		}
        	}
    	}
    }
    	
    if(!isCheck){
    	alert("Please select checkbox.");
    	return false;
    }else if(isFail){
    	alert("Please re-check service status.");
    	return false;
    }else if(action == 'CHECKIN'){
    	var params	 = "arrServiceDetailId=" + strDetailId;
    		params	+= "&arrDateFrom=" + strDateFrom;
    		params	+= "&arrDateTo=" + strDateTo;
    		params	+= "&arrRoomId=" + strRoomId;
    		
        document.getElementById(_RESERVE_INFO_ROOM_INDICATOR).style.display = "inline";
        isdnSendRequest("reserveInfoRoom_checkCheckinJSON.action", params , "POST", callbackCheckCheckin);
        
//        var errorFlag = document.getElementById("errorFlag").value;
//        if(errorFlag != ''){
//        	errorFlag = '';
//        	return false;
//        }
    }
    return true;
}

callbackCheckCheckin = function() {
    var ready = req.readyState;
    //  console.debug(ready);
    var jsonObject=null;
    if ( ready == 4 ){
        if(req.status == 200) {
            jsonObject=eval( "("+ req.responseText +")" );

            if(jsonObject.object.data.errMsg != ''){
            	alert(jsonObject.object.data.errMsg);  
            	
                document.getElementById("errorFlag").value = "Y";
            }
            
            document.getElementById(_RESERVE_INFO_ROOM_INDICATOR).style.display = "none";
        }
    }
};
dojo.event.topic.subscribe("/beforeInfoRoomAction", function(event, widget){
    try{
    	var action = "";
    	if(widget == '[Widget struts:bind, btnReserve]'){
    		action = "RESERVED";
    	}else if(widget == '[Widget struts:bind, btnBook]'){
    		action = "BOOKED";
    	}else if(widget == '[Widget struts:bind, btnCheckin]'){
    		action = "CHECKIN";
    	}else if(widget == '[Widget struts:bind, btnCheckout]'){
    		action = "CHECKOUT";
    	}
		if(!checkReserveDetailAction(action)){
			event.cancel = true;
		}
    }catch(err ) {
         alert("Javascript error in this reserve info page beforeInfoRoomAction main function() [Error: " + err.message + "]");
         event.cancel = true;
    }
});